#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    serialport = new SerialPortInterface::SerialPort("/dev/ttyUSB0");
    transmitter = new Transmit(serialport);
    receiver = new Receive(serialport);

    connect(ui->pushButtonTransmitSend, SIGNAL(clicked()), transmitter, SLOT(Send()));
    connect(ui->pushButtonTransmitSend, SIGNAL(clicked()), ui->lineEdit, SLOT(clear()));
    connect(ui->lineEdit, SIGNAL(textChanged(QString)), transmitter, SLOT(updateBuffer(QString)));
    connect(transmitter, SIGNAL(BufferSended(QString)), ui->textEditTransmitted, SLOT(insertPlainText(QString)));

    connect(ui->radioButtonTransmitchar, SIGNAL(clicked()), transmitter, SLOT(ByteTypecharacter()));
    connect(ui->radioButtonTransmitint, SIGNAL(clicked()), transmitter, SLOT(ByteTypeinteger()));

    connect(ui->radioButtonDisplayascii, SIGNAL(clicked()), receiver, SLOT(Displayascii()));
    connect(ui->radioButtonDisplaybinary, SIGNAL(clicked()), receiver, SLOT(Displaybinary()));
    connect(ui->radioButtonDisplayhex, SIGNAL(clicked()), receiver, SLOT(Displayhex()));
    connect(ui->radioButtonDisplayhexascii, SIGNAL(clicked()), receiver, SLOT(Displayasciihex()));
    connect(ui->radioButtonDisplayint, SIGNAL(clicked()), receiver, SLOT(Displayint8()));
    connect(ui->radioButtonDisplayuint, SIGNAL(clicked()), receiver, SLOT(Displayuint8()));

    connect(receiver, SIGNAL(CharReceived(QString)), ui->textEditReceive, SLOT(insertPlainText(QString)));
}

MainWindow::~MainWindow()
{
    delete receiver;
    delete transmitter;
    delete serialport;

    delete ui;
}

void MainWindow::on_radioButtonDisplayascii_clicked()
{

}
